package triples;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import yago.Match;


public class Triple {
	private String e1;
	private String r;
	private String e2;
	
	
	private float  score;
	private String sentence;
	private String new_sentence;// with time information, actually it is tagged by ner
	private String ori_sentence;//sentence withou any flag
	private boolean timed=false;
	
	public Triple(String e1, String r, String e2, float score, String sentence){
		this.setE1(e1);
		this.setE2(e2);
		this.setR(r);
		this.setScore(score);
		this.setSentence(sentence);
	}
	
	//a is used to diffrentiate between this constructor and the above constructor
	public Triple(String sen, String new_sen,String ori_sen,boolean a){
		this.sentence = sen;
		this.new_sentence = new_sen;
		this.ori_sentence = ori_sen;
	}
	
	//get the enetity in the string
	public String get_s_e1(){
		return this.e1.substring(0,e1.length()-4);
	}
	public String get_s_e2(){
		return this.e2.substring(0,e2.length()-4);
	}
	public String getE1() {
		return e1;
	}

	public void setE1(String e1) {
		this.e1 = e1;
	}

	public String getR() {
		return r;
	}

	public void setR(String r) {
		this.r = r;
	}

	public String getE2() {
		return e2;
	}

	public void setE2(String e2) {
		this.e2 = e2;
	}

	public float getScore() {
		return score;
	}

	public void setScore(float score) {
		this.score = score;
	}

	public String getSentence() {
		return sentence;
	}

	public void setSentence(String sentence) {
		this.sentence = sentence;
	}

	public String getNew_sentence() {
		return new_sentence;
	}

	public void setNew_sentence(String new_sentence) {
		this.new_sentence = new_sentence;
	}

	public boolean isTimed() {
		return timed;
	}

	public void setTimed(boolean timed) {
		this.timed = timed;
	}

	public String getOri_sentence() {
		return ori_sentence;
	}

	public void setOri_sentence(String ori_sentence) {
		this.ori_sentence = ori_sentence;
	}
	
	public ArrayList<String> extractDate(){
		
		if( this.isTimed() ){
			ArrayList<String> dates =new ArrayList<String>();
			String p="<DATE>(.*?)</DATE>";
			Pattern pattern = Pattern.compile(p);
			Matcher matcher = pattern.matcher(this.getNew_sentence());
			while (matcher.find()) {
				//System.out.println(matcher.group(1));
				dates.add(matcher.group(1));
			}
			
			return dates;
		}else{
			System.out.println("not timed, no way to extract");
			return null;
		}
		
	}
	
	public String extractRelation(){
		String sen = this.getSentence();
		String p = "\\{\\{\\{(.*?)\\}\\}\\}";
		Pattern pattern = Pattern.compile(p);
		Matcher matcher = pattern.matcher(sen);
		
		if( matcher.find()){
			return matcher.group(1);
		}else{
			System.out.println("No relation found in the sentence this is not supposed to Happen");
			return " ";
		}
		
		
	}
	
	public String extractE1(){
		String p = "\\[\\[\\[[A-Z]*? (.*?)\\]\\]\\]";
		Pattern pattern = Pattern.compile(p);
		Matcher matcher = pattern.matcher(this.getSentence());
		if( matcher.find()){
			return matcher.group(1);
		}else{
			System.out.println("this is not supposed to happen, no enetity  1 could be extracted");
			return null;
		}
	}
	
	public String extractE2(){
		String p = "\\[\\[\\[[A-Z]*? (.*?)\\]\\]\\]";
		Pattern pattern = Pattern.compile(p);
		Matcher matcher = pattern.matcher(this.getSentence());
		if( matcher.find()){
			matcher.find();
			return matcher.group(1);
		}else{
			System.out.println("this is not supposed to happen, no enetity   2 could be extracted");
			return null;
		}
	}
	
	public static void main(String[] args){
		ArrayList<String> l = new ArrayList<String>();
		
		//l.add("a");
		//l.add("b");
		//l.add("c");
		//for(String s: l){
		//	System.out.println(s);
		//}
		//l.add(null);
		//l.add(null);
		//System.out.println(l.size());
	/*	String sen = "When <PERSON>Reid</PERSON> left <ORGANIZATION>Coventry</ORGANIZATION> in <DATE>January 2005</DATE> , <LOCATION>Heath</LOCATION> stepped";
		String p="<DATE>(.*?)</DATE>";
		Pattern pattern = Pattern.compile(p);
		Matcher matcher = pattern.matcher(sen);
		while (matcher.find()) {
			System.out.println(matcher.group(1));
		}*/
		/*String d1 = "July 2008";
		String p1 = "[0-9]{4}";
		Pattern pattern = Pattern.compile(p1);
		Matcher matcher = pattern.matcher(d1);
		
		if( matcher.find()){
			System.out.println(matcher.group()+",");
		}*/
	/*	String d1 = "[[[LOC Cambridge]]] {{{manager}}} [[[PER Tommy Taylor]]] , now at Leyton Orient .";
		String p1 = "\\[\\[\\[.{4}(.*?)\\]\\]\\]";
		Pattern pattern = Pattern.compile(p1);
		Matcher matcher = pattern.matcher(d1);
		while(matcher.find()){
			System.out.println(matcher.group(1));
		}
		String a="123456789";
		System.out.println(a.substring(0,a.length()-4));
		*/
		//System.out.println("VBD".indexOf("VB"));
		String a= "werwerwe[[[sdfa]]]ssfdad[[[dasdfs]]]";
		System.out.println(a.indexOf("[[[",3));
		
		
	}
	
	
}
